cmake_minimum_required(VERSION 3.10)
project(CrossArchSim C ASM)

# 启用 ccache（可选）
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
  message(STATUS "Using ccache: ${CCACHE_PROGRAM}")
  set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
  set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK    "${CCACHE_PROGRAM}")
endif()

# 公共 include
include_directories(${PROJECT_SOURCE_DIR}/include)

# 构建 math 共享库
add_library(mathlib SHARED src/math.c)
target_link_libraries(mathlib m)
set_target_properties(mathlib PROPERTIES OUTPUT_NAME math)

# 选择 SIMD 源
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
  set(SIMD_SRC src/simd.c)
else()
  set(SIMD_SRC src/simd_x86.c)
endif()

# 构建主程序
add_executable(app
  src/main.c
  ${SIMD_SRC}
  src/io.c
  src/fault.c
  asm/utils.S
)
target_link_libraries(app pthread mathlib)

enable_language(CXX)

add_library(cpp_tests STATIC
    cpp/object_model.cpp
    cpp/exception_test.cpp
    cpp/template_test.cpp
    cpp/stl_test.cpp
)

target_include_directories(cpp_tests PUBLIC ${PROJECT_SOURCE_DIR}/include)
target_link_libraries(app cpp_tests)
